package com.ruoyi.web.controller.applet;


import com.ruoyi.applet.appletShoppingCart.domain.AppletShoppingCart;
import com.ruoyi.applet.appletShoppingCart.service.IAppletShoppingCartService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 购物车Controller
 * @author ruoyi
 * @date 2024-11-28
 */
@Controller
@RequestMapping("/applet/shoppingCart")
public class AppletShoppingCartController extends BaseController {
    
    private final String prefix = "applet/appletShoppingCart";
    
    @Resource
    private IAppletShoppingCartService appletShoppingCartService;
    
    @RequiresPermissions("applet:appletShoppingCart:view")
    @GetMapping()
    public String shoppingCart() {
        return prefix + "/shoppingCart";
    }
    
    /**
     * 查询购物车列表
     */
    @RequiresPermissions("applet:appletShoppingCart:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppletShoppingCart appletShoppingCart) {
        startPage();
        List<AppletShoppingCart> list = appletShoppingCartService.selectAppletShoppingCartList(appletShoppingCart);
        return getDataTable(list);
    }
    
    /**
     * 导出购物车列表
     */
    @RequiresPermissions("applet:appletShoppingCart:export")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppletShoppingCart appletShoppingCart) {
        List<AppletShoppingCart> list = appletShoppingCartService.selectAppletShoppingCartList(appletShoppingCart);
        ExcelUtil<AppletShoppingCart> util = new ExcelUtil<AppletShoppingCart>(AppletShoppingCart.class);
        return util.exportExcel(list, "购物车数据");
    }
    
    /**
     * 新增购物车
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存购物车
     */
    @RequiresPermissions("applet:appletShoppingCart:add")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppletShoppingCart appletShoppingCart) {
        return toAjax(appletShoppingCartService.insertAppletShoppingCart(appletShoppingCart));
    }
    
    /**
     * 修改购物车
     */
    @RequiresPermissions("applet:appletShoppingCart:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AppletShoppingCart appletShoppingCart = appletShoppingCartService.selectAppletShoppingCartById(id);
        mmap.put("appletShoppingCart", appletShoppingCart);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存购物车
     */
    @RequiresPermissions("applet:appletShoppingCart:edit")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppletShoppingCart appletShoppingCart) {
        return toAjax(appletShoppingCartService.updateAppletShoppingCart(appletShoppingCart));
    }
    
    /**
     * 删除购物车
     */
    @RequiresPermissions("applet:appletShoppingCart:remove")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(appletShoppingCartService.deleteAppletShoppingCartByIds(ids));
    }
}
